package com.situ.springboot.config;

import com.situ.springboot.entity.Student;
import com.situ.springboot.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// Controller Service Repository Component: <bean />
// Resource Autowired RequestMapping RequestParam
// ResponseBody Qualifier MapperScan SpringBootApplication
// @Bean
// @Configuration用于定义配置类，可替换xml配置文件，被注解的类内部包含有一个或多个被@Bean注解的方法
//@Configuration
public class WebConfigurer implements WebMvcConfigurer {

    // 这个方法用来配置拦截器，拦截器只有在这里配置了才能生效
    // addPathPatterns("/**")拦截所有的请求
    // include exclude
    // excludePathPatterns 代表排除哪些请求不需要拦截
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //  /user/login  /user/getLoginPage
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login", "/user/getLoginPage", "/auth/code", "/static/**");
    }

    // <bean name="student" class="">
    @Bean
    public Student createStudent() {
        Student student = new Student(1, "zhangsan" , 23, "nan");
        return student;
    }
}
